﻿using System;
using System.Collections.Generic;
using System.Text;

namespace LoginServer
{
    public class YAuthentication
    {
        Random r = new Random();
        public YAuthentication()
        {
            InitDic();
        }
       
        private void InitDic()
        {
            for (int i = 0; i < 256; i++)
            {
                Dic.Add((byte)i, UTF8Encoding.UTF8.GetBytes(i.ToString()+"_ilu2009"));
            }
        }
        Dictionary<byte, byte[]> Dic = new Dictionary<byte, byte[]>();
        public byte[] Calculate(Int64 input)
        {
            byte[] input_data= BitConverter.GetBytes(input);
            List<byte> res = new List<byte>();
            byte[] key = Dic[input_data[4]];
            for (int i = 0; i < input_data.Length; i++)
            {
                byte temp = (byte)(input_data[i] ^ key[i]);
                res.Add(temp);
            }
            return res.ToArray();
        }
        public int GetCode()
        {
            int tmp = r.Next();
            return tmp;
        }
    }
}
